<template>
	<view>
		<!-- 主要内容 -->
		<my-input-box @changeInput="changeInput_1" :title="title_1" :placeholderValue="default_1"></my-input-box>
		<my-input-box @changeInput="changeInput_2" :title="title_2" :placeholderValue="default_2"></my-input-box>
		<my-input-box @changeInput="changeInput_3" :title="title_3" :placeholderValue="default_3"></my-input-box>

		<!-- 提交 -->
		<my-bottom-btn :title="title" @clickBtn="clickBtn"></my-bottom-btn>
	</view>
</template>

<script>
	import myInputBox from '@/components/common/my-input-box/my-input-text.vue'
	import myBottomBtn from '@/components/common/my-bottom-btn/my-bottom-btn.vue'

	import {
		updatePwd
	} from '@/api/http/login/login.js'

	export default {
		components: {
			myInputBox,
			myBottomBtn
		},
		data() {
			return {
				title: '确定',
				title_1: '原密码',
				default_1: '填写原密码',
				title_2: '新密码',
				default_2: '填写新密码',
				title_3: '确定新密码',
				default_3: '再次确定新密码',

				pwd: '',
				newPwd: '',
				confirmPwd: ''
			}
		},
		methods: {
			//1，填写原密码
			changeInput_1(e) {
				this.pwd = e
			},
			//2，输入新密码
			changeInput_2(e) {
				this.newPwd = e
			},
			//3，确定新密码
			changeInput_3(e) {
				this.confirmPwd = e
			},
			//4，确定修改
			clickBtn() {
				//判断数据
				if (this.pwd == '' || this.newPwd == '' || this.confirmPwd == '') {
					return uni.$showMsg('请输入正确参数！')
				}
				if (this.newPwd !== this.confirmPwd) {
					return uni.$showMsg('两次密码输入不同！')
				}
				//发起网络请求
				updatePwd(this.pwd, this.newPwd).then(res => {
					if (res.data.pubInfo.code !== 0) {
						return uni.$showMsg(res.data.pubInfo.message);
					}
					uni.$showMsg('修改成功！');
					this.pwd = ''
					this.newPwd = ''
					this.confirmPwd = ''
				})

			}
		}
	}
</script>

<style>

</style>
